<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('菜房出库列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <div class="btn-group " style="margin: 0px auto;display: table;" role="group">
                <button type="button" class="top-link btn btn-sm btn-white">当天任务</button>
                <button type="button" class="top-link btn-sm btn-white">入库</button>
                <button type="button" class="top-link btn-sm btn-white">仓储</button>
                <button type="button" class="top-link btn-sm btn-primary">出库</button>
            </div>

        </div>
        <div class="btn-group-sm " id="toolbar1" role="group">
            <h3 class="inline">出库：</h3>
        </div>
        <div class="col-sm-12 select-table table-striped ">
            <table id="bootstrap-table-1" data-mobile-responsive="true"></table>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <h3 class="inline">出库订单表：</h3>

            <a class="btn btn-primary" onclick="openOrder()">
                <i class="fa fa-table"></i> 出库记录单
            </a>
            <a class="btn btn-warning" onclick="confirmTable();">
                <i class="fa fa-send"></i> 确认
            </a>
            <!--<a class="btn btn-success disabled" onclick="$.operate.add()" shiro:hasPermission="system:ncOuputCf:add">
                <i class="fa fa-plus"></i> 添加
            </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:ncOuputCf:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:ncOuputCf:remove')}]];
    var prefix = ctx + "system/ncOuputCf";
    var datas = [[${@dict.getType('cforderType')}]];
    var cforderFor = [[${type}]];
    $(function () {
        var options = {
            url: prefix + "/list?type="+cforderFor,
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "菜房出库",
            queryParams: function queryParams(params) {
                var search = $.table.queryParams(params);
                search.status = 1;
                search.params = {cforderFor: cforderFor};
                return search;
            },
            showSearch: false,
            showRefresh: false,
            showColumns: false,
            showToggle: false,
            showExport: false,
            columns: [{
                title: '序号',
                formatter: function (value, row, index) {
                    return $.table.serialNumber(index);
                }
            },
                {
                    field: 'outputId',
                    title: '出库id',
                    visible: false
                },
                {
                    field: 'ncorderCf.cforderCode',
                    title: '订单编号',
                    formatter: function (value, row, index) {
                        if (row.ncorderCf.isCheck == '1') {
                            return '--'
                        } else {
                            return row.ncorderCf.cforderCode
                        }

                    }

                }, {

                    field: 'piciCode',
                    title: '蔬菜批次',
                },
                {
                    field: 'ncorderCf.cropNameCn',
                    title: '作物名称',
                },
                {
                    field: 'ncorderCf.cropVarietiesCn',
                    title: '作物品种',
                },
                {
                    field: 'teamCn',
                    title: '生产班组',

                },
                {

                    field: 'outputType',
                    title: '出库类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'realAmout',
                    title: '实际提供数量（kg）',
                    sortable: true
                },
                {
                    field: 'outputTime',
                    title: '出库时间',
                    sortable: true
                },
                {
                    field: 'outputUser',
                    title: '出库经手人',
                    sortable: true
                },

                {
                    field: 'remark',
                    title: '备注',
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="editOutPut(\'' + row.outputId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="delOutPut(\'' + row.outputId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
        initOrderCf();
        $('.top-link').click(function () {
            var index = $(this).index();
            switch (index) {
                case 0:
                    window.location.href = ctx + 'system/ncOrderCf/ncOrderCf-ordered?status=2&type=' + cforderFor;
                    return;
                case 1:
                    window.location.href = ctx + 'system/ncInputCf?type=' + cforderFor;
                    return;
                case 2:
                    window.location.href = ctx + 'system/ncInputCf/ncInputCf-stock?type=' + cforderFor;
                    return;
                case 3:
                    window.location.reload();

                    return;
            }
        })
    });

    function initOrderCf() {
        var prefix = ctx + "system/ncOrderCf";
        var datas = [[${@dict.getType('cforderType')}]];
        var cforderStatus = [[${@dict.getType('cforderStatus')}]];
        var normal_unit = [[${@dict.getType('normal_unit')}]];

        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            id: 'bootstrap-table-1',
            modalName: "菜房订单",
            pageSize: 1000,
            toolbar: 'toolbar1',
            showExport: false,
            showSearch: false,
            showRefresh: false,
            showColumns: false,
            showToggle: false,
            queryParams: function queryParams(params) {
                var search = $.table.queryParams(params);
                search.cforderStatus = 4;
                search.status = 2;
                search.cforderFor = cforderFor;
                search.isCheck = 2;
                return search;
            },
            columns: [{
                title: '序号',
                formatter: function (value, row, index) {
                    return $.table.serialNumber(index);
                }
            },
                {
                    field: 'cforderCode',
                    title: '订单编号',
                    formatter: function (value, row, index) {
                        if (row.isCheck == '1') {
                            return '--'
                        } else {
                            return row.cforderCode
                        }

                    }

                }, {

                    field: 'piciCode',
                    title: '蔬菜批次',
                },
                {
                    field: 'cropNameCn',
                    title: '作物名称',
                    sortable: true
                },
                {
                    field: 'cropVarietiesCn',
                    title: '作物品种',
                    sortable: true
                },
                {
                    field: 'teamCn',
                    title: '生产班组',
                    sortable: true

                },
                {
                    field: 'requestTime',
                    title: '需求日期',
                    formatter: function (value, row, index) {
                        return dateFtt(value);
                    },sortable: true
                },
                {
                    field: 'cforderId',
                    title: '菜房订单键',
                    visible: false
                },
                {
                    field: 'cforderType',
                    title: '订单类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    },sortable: true
                },

                {
                    field: 'requestAmount',
                    title: '需求数量',
                    sortable: true
                },
                {
                    field: 'unit',
                    title: '单位',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(normal_unit, value);
                    }
                },
                {
                    field : 'remark',
                    title : '备注',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="confirmOutput(\'' + row.cforderId + '\')"><i class="fa fa-check"></i>出库</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    }

    function confirmOutput(cforderId) {
        var url = prefix + "/confirmOutput/" + cforderId;
        $.modal.open("确认出库", url);
    }

    /*表单确认*/
    function confirmTable() {
        var confirmTable = prefix + "/confirmTable?caifangType=" + cforderFor;
        var data = $('#bootstrap-table').bootstrapTable('getData');
        if (data && data.length > 0) {

            $.modal.confirm("确认生成检测单吗？", function () {
                var ids = [];
                $(data).each(function (i, e) {
                    ids.push(e.outputId);
                });
                var ids_str = ids.join(",");
                myPost(confirmTable, {ids: ids_str},
                    function (data) {

                        if (data.code == 0) {
                            layer.msg("提交成功")
                        } else {
                            layer.msg(data.msg);
                        }
                        reload()
                    }, function (e) {
                        layer.msg("确认失败!");
                        reload()
                    })

            })
        } else {
            layer.msg("未发现数据!")
        }

    }

    /*打开检测记录单*/
    function openOrder() {
        var orderType = 6;
        if (cforderFor == 2) {
            orderType = 8;
        }
        var url = ctx + 'system/ncOrder?orderType=' + orderType;
        $.modal.openTab("检测记录单", url);
    }

    function reload() {
        window.location.reload()
    }

    function editOutPut(id) {
        var updateUrl = ctx + "system/ncOuputCf/edit/" + id;
        $.modal.open("修改", updateUrl, null, null, null, function () {
            reload();
        });
    }

    function delOutPut(id) {
        var removeUrl = ctx + "system/ncOuputCf/remove";
        var data = {ids: id};
        $.modal.confirm("确定删除该条信息吗？", function () {
            $.operate.submit(removeUrl, "post", "json", data);

        });
    }

    function reload() {
        $('#bootstrap-table').bootstrapTable('refresh', {
            silent: true
        });
        $('#bootstrap-table-1').bootstrapTable('refresh', {
            silent: true
        });
    }

    if(cforderFor == 1){
        setTitle("蔬菜整理间1-出库",false)
    }else {
        setTitle("蔬菜整理间2-出库",false)
    }

</script>
</body>
</html>